[4주차] 남유정/[feat] 게시물/댓글/신고 도메인 기반 기능 설계 및 API 구현#166
Hidden character warning
[4주차] 남유정/[feat] 게시물/댓글/신고 도메인 기반 기능 설계 및 API 구현#166N-yujeong wants to merge 2 commits intoLeets-Official:남유정/mainfrom
Conversation
gusanans218
left a comment
There was a problem hiding this comment.
댓글, 게시글, 신고를 각각 domain 단위로 분리해서 설계하신 점이 인상적이었습니다!!
특히 Report를 별도 도메인으로 분리하고 targetType으로 POST/COMMENT를 구분한 구조가 확장성을 잘 고려한 설계라고 느껴졍습니다!
Hanharam
left a comment
There was a problem hiding this comment.
👍 계층을 잘 분리하면서 코드를 작성하신 점과 신고 중복 방지를 위해 DB에 제약을 설정하신 점이 좋았습니다!
jihoonkim501
left a comment
There was a problem hiding this comment.
유정님 수고 많으셨습니다~! 확실히 프론트를 하셨다보니까 스웨거 정리가 매우 깔끔하고 눈에 확들어오는 것 같아요 👍👍 제 코멘트만 확인해주시면 감사하겠습니다~!~!
| @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "채택 성공"), | ||
| @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "해당 게시글의 댓글이 아님"), | ||
| @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "403", description = "채택 권한 없음 (게시글 작성자가 아님)"), | ||
| @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "404", description = "게시글 또는 댓글 없음"), | ||
| @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "409", description = "이미 채택된 댓글 존재") |
|
|
||
| // 해당 게시글의 댓글인지 확인 | ||
| if (!comment.getPost().getId().equals(postId)) { | ||
| throw new IllegalArgumentException("해당 게시글에 속한 댓글이 아닙니다."); |
| import java.util.Map; | ||
|
|
||
| @Tag(name = "Post", description = "게시글 관련 API") | ||
| public interface PostControllerDocs { |
| public enum PostStatus { | ||
| ACTIVE, | ||
| HIDDEN | ||
| } |
There was a problem hiding this comment.
만약 softDelete를 생각하신다면 Deleted 상태도 추가하는걸 추천드립니다~!
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| public class ReportService { |
There was a problem hiding this comment.
충분히 잘 구성해주셨습니다~! 추후에 리팩토링을 한다면 한 메소드에 검증, 저장, 예외를 던지는 책임이 과다할 수 있어서 분기하는 것 또한 추천드립니다! ( 오버엔지니어링이라고 생각된다면 괜찮습니다~!~!)
| .body(ApiResponse.error("POST_NOT_FOUND", "해당 게시글을 찾을 수 없습니다.")); | ||
| } | ||
|
|
||
| @ExceptionHandler(CommentNotFoundException.class) |
There was a problem hiding this comment.
핸들러로 매번 추가하는것도 초반엔 괜찮을 수 있는데 프로젝트 규모가 커지면 조금 버거울 수 있습니다. ErrorCode 또는 status로 관리하는 방법도 있다는 점 알고계시면 좋을 것 같아요~!
1. 과제 요구사항 중 구현한 내용
2. 핵심 변경 사항
신규 도메인 - Report
Report엔티티: reporter(User), targetType(POST/COMMENT), targetId, reason,status(PENDING/RESOLVED)
(reporter_id, target_type, target_id)unique constraint로 DB 레벨 중복 신고 방지ReportService: 게시글/댓글 신고, 신고 처리 완료(PENDING → RESOLVED)기존 엔티티 수정
Post:PostStatus필드 추가 (ACTIVE/HIDDEN),hide()메서드Comment:adopted필드 추가,adopt()메서드예외 처리
UserNotFoundException,CategoryNotFoundException,AlreadyHiddenException,AlreadyResolvedException,DuplicateReportException,AlreadyAdoptedExceptionIllegalArgumentException사용 부분 → 커스텀 예외로 통일3. 실행 및 검증 결과
게시글 신고
댓글 신고
신고 처리 완료 (PENDING → RESOLVED)
게시글 숨김 (ACTIVE → HIDDEN)
댓글 작성
댓글 채택
4. 완료 사항
5. 추가 사항
제출 체크리스트
{이름}/main브랜치다{이름}/{숫자}주차브랜치다Reviewer 참고